<?php

declare(strict_types=1);
/**
 * Author: Zane
 * Email: 873934580@qq.com
 * Date: 2023/6/28.
 */

namespace App\Models;

/**
 * @property string title
 * @property string md5
 * @property string type
 * @property string suffix
 * @property string driver
 * @property string size
 * @property string url
 * @property string path
 * @property string groups
 * @property string quote
 */
class Attachment extends BaseModel
{
    /**
     * 根据文件md5获取信息.
     *
     * @param $md5
     *
     * @return null|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object
     */
    public static function byMd5($md5)
    {
        return (new static())->newQuery()->where('md5', $md5)->first();
    }

    public function getSizeAttribute(): string
    {
        return byteFormat($this->attributes['size']);
    }

    public function getUrlAttribute(): string
    {
        return normUrl($this->attributes['url']);
    }
}
